﻿Ext.define('app.system.dic.Add', {
    extend: 'Ext.window.Window',
    title: '新增参数',
    width: 400,
    catalog: '',
    referenceHolder: true,
    modal: true,
    autoHeight: true,
    resizable: false,
    initComponent: function () {
        var main = this;
        this.items = [this.getFormPanel()];
        this.buttons = [{ text: '保存', handler: function () { main.saveSubmit(); } }];
        this.callParent();

    },
    listeners: {
        afterrender: function (win) {
            if (win.catalog) {
                var refs = win.getReferences();
                var store = refs.CatalogCombo.getStore();
                store.on('load', function () {
                    refs.CatalogCombo.setRawValue(win.catalog);
                });
                store.load();
            }

        }
    },
    saveSubmit: function () {
        var main = this;
        var form = this.getFormPanel().getForm();
        var catalog = this.getReferences().CatalogCombo.getRawValue();
        if (form.isValid()) {

            var vals = form.getValues();
            vals.Catalog = catalog;
            App.AjaxPost('/api/services/app/SystemParams/SaveSubmit', vals, function () {                
                Ext.Msg.alert("系统提示", "添加成功")
                main.hide();
            });  
        }

    },
    getFormPanel: function () {
        if (!this.form) {
            this.form = new Ext.form.Panel(
            {
                labelWidth: 150,
                labelAlign: 'right',
                frame: false,
                defaults: { width: '90%', labelAlign: 'right' },
                defaultType: 'textfield',
                bodyStyle: 'padding:5px',
                border: false,
                items: [
                    {
                        xtype: 'combo',
                        fieldLabel: '参数分类',
                        reference: 'CatalogCombo',
                        triggerAction: 'all',
                        lazyRender: true,
                        mode: 'local',
                        editable: false,
                        autoSelect: true,
                        allowBlank: false,
                        store: new Ext.data.JsonStore(
                        {
                            autoLoad: false,
                            proxy: {
                                type: 'ajax',
                                url: '/api/services/app/SystemParams/GetCatalog',
                                reader: {
                                    type: 'json',
                                    rootProperty: function (node) {
                                        return node.result || node.children;
                                    }
                                }
                            },
                            fields: ['id', 'text']
                        }),
                        valueField: 'id',
                        displayField: 'text'
                    },
                    {
                        fieldLabel: '参数名称',
                        xtype: 'textarea',
                        height: 100,
                        allowBlank: false,
                        name: 'DisplayName'
                    },

                    {
                        fieldLabel: '参数值',
                        name: 'CodeValue'
                    },
                    {
                        xtype: 'panel',
                        border: false,
                        bodyStyle:'padding-left:200px;',
                        html: '长假设置(demo)：<br>20170127-20170204<br/>20170501-20170503'
                    }
                ]
            });
        }
        return this.form;
    }
});
